package cate.game.play.vo;

import cate.game.play.proce.play.PlayPO;
import cp.solution.manage.api.open.replay.ReplaySaveReq;
import easy.java.codec.JsonCodec;
import easy.java.codec.ZlibCodec;

public class ReplayUtils {

    public static ReplaySaveReq toReplaySaveReq(PlayPO po, Long expiredTime) throws Exception {
        return toReplaySaveReq(new PlayVO().read(po), expiredTime);
    }

    public static ReplaySaveReq toReplaySaveReq(PlayVO vo, Long expiredTime) throws Exception {
        ReplaySaveReq req = new ReplaySaveReq();
        req.setFuncId(vo.story.funcId);
        req.setRoleId(vo.side1.snapshot.uid);
        req.setExpiredTime(expiredTime);
        byte[] jsonBytes = JsonCodec.instance().encodeBytes(vo);
        byte[] zlibBytes = ZlibCodec.instance().compress(jsonBytes);
        req.setPlayData(zlibBytes);
        return req;
    }
}
